//package com.wb.adutils.ad
//
//import android.app.Activity
//import android.app.Application
//import android.os.Bundle
//import android.util.Log
//import androidx.lifecycle.*
//import com.black.video.BuildConfig
//import com.black.video.base.BaseApplication
//import com.black.video.tools.LogC
//import java.lang.ref.WeakReference
//
///**
// * 管理Admob的开屏广告和ReopenAd
// */
//object ReOpenAdTools : DefaultLifecycleObserver, Application.ActivityLifecycleCallbacks {
//
//    private var backgroundTime = 0L
//    // 离开的页面名称
//    private var leaveClassName: String? = null
//    private var activityReference: WeakReference<Activity>? = null
//
//
//    fun init() {
//        Log.d("Reopen", "reopen -> init...")
//        activityReference?.clear()
//        ProcessLifecycleOwner.get().lifecycle.removeObserver(this)
//        BaseApplication.context.unregisterActivityLifecycleCallbacks(this)
//
//        // 获取ReopenAd
//
//
//        // 注册Application的生命周期
//        ProcessLifecycleOwner.get().lifecycle.addObserver(this)
//        // 注册Activity的生命周期
//        BaseApplication.context.registerActivityLifecycleCallbacks(this)
//    }
//
//    override fun onStart(owner: LifecycleOwner) {
//        super.onStart(owner)
//        // 应用进入前台
//        Log.d("Reopen", "reopen -> onAppForeground...")
//        if (System.currentTimeMillis() - backgroundTime < 5 * 60 * 1000 && !BuildConfig.DEBUG) { // 此次不在展示广告
//            return
//        }
////        val activity = activityReference?.get() ?: return
////        if (!isLoadAdSuccess) return
////        isLoadShow = true
////        GMInterstitialAdUtils.showInterstitialAd(activity)
//    }
//
//    override fun onStop(owner: LifecycleOwner) {
//        super.onStop(owner)
//        Log.d("Reopen", "reopen -> onAppBackground...")
//        val activity = activityReference?.get() ?: return
//        // 判断当前离开的页面的名字
//        if (!activity.javaClass.name.startsWith("com.black.video")) { // 非自己的页面，不会加载广告
//            return
//        }
//        // 记录此时进入后台的时间点
//        backgroundTime = System.currentTimeMillis()
//        loadAd(activity)
//    }
//
//    override fun onDestroy(owner: LifecycleOwner) {
//        super.onDestroy(owner)
//        Log.d("Reopen", "reopen -> onAppDestroy...")
////        GMInterstitialAdUtils.release()
//    }
//
//    // 广告是否正在显示
//    private var isLoadShow = false
//    private var isLoadAdSuccess = false
//    private fun loadAd(activity: Activity){
//        isLoadShow = false
//        isLoadAdSuccess = false
////        GMInterstitialAdUtils.loadAd(activity, "102068249", GMAdConstant.VERTICAL, object : OnLoadAdListener {
////            override fun onAdLoaded(ad: Any?) {
////                isLoadAdSuccess = true
////                Log.d("Reopen", "loadAd -> 广告加载成功...")
////            }
////
////            override fun onAdLoadFail() {
////                isLoadAdSuccess = false
////                Log.d("Reopen", "loadAd -> 广告加载失败...")
////            }
////
////            override fun onAdComplete() {
////                super.onAdComplete()
////                isLoadShow = false
////                isLoadAdSuccess = false
////                Log.d("Reopen", "loadAd -> 广告加载完成...")
////            }
////        })
//    }
//
//
//    override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {}
//    override fun onActivityStarted(activity: Activity) {}
//    override fun onActivityResumed(activity: Activity) {}
//    override fun onActivityPaused(activity: Activity) {}
//    override fun onActivityStopped(activity: Activity) {
//        // 获取当前页面的名字，判断是否是自己的页面
//        if (activityReference != null)  {
//            activityReference?.clear()
//        }
//        activityReference = WeakReference(activity)
//        LogC.d("Reopen -> packageName=${BaseApplication.context.packageName}， Started...${activity.javaClass.name}")
//    }
//    override fun onActivityDestroyed(activity: Activity) {}
//    override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {}
//}